package com.ht.api.service.report;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ht.api.db.Db;
import com.ht.api.db.DbConfig;
import com.ht.api.db.DbList;
import com.ht.api.db.SqlParser;
import lombok.extern.slf4j.Slf4j;

import javax.sql.DataSource;

@Slf4j
public class OrderCountReport {


    public static DbList viewData(DataSource ds, JSONObject parserParam, JSONObject condition) {
//        String sql = """
//                SELECT
//                	num,
//                	COUNT(1) usercount
//                FROM
//                	(SELECT openid, COUNT(1) num FROM order_item
//
//                	where openid in (condition)
//
//                	GROUP BY openid) t
//                GROUP BY
//                	num
//
//                """;

        SqlParser sqlParser = parserParam.toBean(SqlParser.class).setTable("order_item");
        sqlParser.select("SELECT openid, COUNT(1) num").group("openid");

//        sqlParser.subwhere("openid", "in", "condition");

        String countsql = "select num,COUNT(1) usercount from (" + sqlParser.getSql() + ") t ";

        DbList list = Db.query(ds, countsql);

        log.info(list.toString());

        return list;
    }

    public static DbList userData(DataSource ds, JSONObject param, JSONObject condition) {
        return null;
    }

}
